package {
	import mx.messaging.messages.AsyncMessage;
	import log.Logger;
	
	
	import mx.messaging.Consumer;
	import mx.messaging.Producer;
	import mx.messaging.events.MessageAckEvent;
	import mx.messaging.events.MessageEvent;
	import mx.messaging.events.MessageFaultEvent;

	import flash.display.Sprite;

	/**
	 * @author Andrew
	 *     -context-root=samples
	 */
	public class Main extends Sprite {
		private var producer : Producer;
		private var consumer : Consumer;
		

		public function Main() {
			
			Logger.init(this, true, true);
			Logger.DEBUG("Hello"); 
			
			
			producer = new Producer();
			producer.destination = "chat";//"publishIdService";
			producer.addEventListener(MessageAckEvent.ACKNOWLEDGE, acknowledgeHandler);
			producer.addEventListener(MessageFaultEvent.FAULT, faultHandler);
			
			consumer = new Consumer();
			consumer.destination = "chat";//"publishIdService"; 
			//consumer.channelSet 
			consumer.addEventListener(MessageEvent.MESSAGE, messageHandler);
			consumer.addEventListener(MessageFaultEvent.FAULT, faultHandler);
			//consumer.subscribe();
			
			
			var msg : AsyncMessage = new AsyncMessage();
			msg.body.chatMessage = "Helllo";
			//producer.send(msg);
			
		}

		private function messageHandler(event : MessageEvent) : void {
			Logger.DEBUG(event.message.body.chatMessage);//message.body.chatMessage
		}

		private function acknowledgeHandler(event : MessageAckEvent) : void {
		}

		private function faultHandler(event : MessageFaultEvent) : void {
		}
	}
}
